package com.biz.primus.ms.adv.api;

import com.biz.primus.base.vo.PageVo;
import com.biz.primus.common.vo.SpringPageVO;
import com.biz.primus.model.adv.enums.AdUsePlace;
import com.biz.primus.model.adv.enums.UseType;
import com.biz.primus.model.adv.vo.AdPositionVo;
import com.biz.primus.model.adv.vo.AdvertisementQueryVo;
import com.biz.primus.model.adv.vo.AdvertisementVo;
import com.biz.primus.ms.adv.service.AdvService;
import com.biz.primus.ms.base.api.BaseApiController;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.math.BigDecimal;
import java.util.List;

/**
 * @author liujun
 * @date 2017/9/18
 */
@RestController
@RequestMapping("soa/advService/")
@Api("广告相关接口文档")
public class AdvApiController extends BaseApiController {

    private final AdvService advService;

    @Autowired
    public AdvApiController(AdvService advService) {
        this.advService = advService;
    }

    @ApiOperation("根据使用类型返回广告位")
    @GetMapping("queryAdByUseType")
    public List<AdPositionVo> queryAdByUseType(@ApiParam(value = "可用类型", required = true)
                                               @RequestParam("utype") UseType utype) {
        return this.advService.queryAdByUseType(utype);
    }

    @ApiOperation("保存或更新广告信息")
    @PostMapping("addOrUpdateAdInfo")
    public void addOrUpdateAdInfo(@RequestBody AdvertisementVo advo) {
        this.advService.addOrUpdateAdInfo(advo);
    }

    @ApiOperation(" 保存或更新广告位信息")
    @PostMapping("addOrUpdateAdPositionInfo")
    public void addOrUpdateAdPositionInfo(@RequestBody AdPositionVo input) {
        this.advService.addOrUpdateAdPositionInfo(input);
    }

    @ApiOperation(" 根据id删除广告信息")
    @GetMapping("deleteAdById")
    public void deleteAdById(@ApiParam(value = "广告id", required = true)
                             @RequestParam("id") long id) {
        this.advService.deleteAdById(id);
    }

    @ApiOperation(" 根据id删除广告位信息")
    @GetMapping("deleteAdPositionById")
    public void deleteAdPositionById(@ApiParam(value = "广告位id", required = true)
                                     @RequestParam("id") long id) {
        this.advService.deleteAdPositionById(id);
    }

    @ApiOperation("查询所有广告信息")
    @GetMapping("getAllAds")
    public List<AdvertisementVo> getAllAds() {
        return this.advService.getAllAds();
    }

    @ApiOperation("根据广告位id查询广告信息")
    @GetMapping("getAdsByPositionId")
    public List<AdvertisementVo> getAdsByPositionId(@ApiParam(value = "广告位id", required = true)
                                                    @RequestParam("positionId") long positionId) {
        return this.advService.getAdsByPositionId(positionId);
    }

    @ApiOperation("查询所有的广告位信息")
    @GetMapping("getAdPositions")
    public List<AdPositionVo> getAdPositions() {
        return this.advService.getAdPositions();
    }

    @ApiOperation("根据id查询广告位信息")
    @GetMapping("getAdPositionById")
    public AdPositionVo getAdPositionById(@ApiParam(value = "广告位id", required = true)
                                          @RequestParam("positionId") long positionId) {
        return this.advService.getAdPositionById(positionId);
    }

    @ApiOperation("根据id查询广告信息")
    @GetMapping("getAdById")
    public AdvertisementVo getAdById(@ApiParam(value = "广告id", required = true)
                                     @RequestParam("adId") long adId) {
        return this.advService.getAdById(adId);
    }

    @ApiOperation("分页查询广告信息")
    @PostMapping("getAdsByParams")
    public SpringPageVO<AdvertisementVo> getAdsByParams(@RequestBody AdvertisementQueryVo queryVo) {
        return this.advService.getAdsByParams(queryVo);
    }

    @ApiOperation("后台查询所有广告位信息")
    @PostMapping("getAllAdPositions")
    public SpringPageVO<AdPositionVo> getAllAdPositions(@RequestBody PageVo vo) {
        return this.advService.getAllAdPositions(vo);
    }

    @ApiOperation("根据经纬度和标识查询广告位")
    @GetMapping("findAdByProvinceId")
    public AdPositionVo findAdByProvinceId(
            @ApiParam(value = "经度", required = true)
            @RequestParam("latitude") BigDecimal latitude,
            @ApiParam(value = "纬度", required = true)
            @RequestParam("longitude") BigDecimal longitude,
            @ApiParam(value = "广告使用位", required = true)
            @RequestParam("adUsePlace") AdUsePlace adUsePlace) {
        return this.advService.findAdByProvinceId(latitude, longitude, adUsePlace);
    }

    @ApiOperation("根据标识查询广告位")
    @GetMapping("getAdpositionCountry")
    public AdPositionVo getAdpositionCountry(@ApiParam(value = "广告使用位", required = true)
                                             @RequestParam("adUsePlace") AdUsePlace adUsePlace) {
        return this.advService.getAdpositionCountry(adUsePlace);
    }

    @ApiOperation("判断该使用位置是否已有广告位")
    @GetMapping("findAdPositionByUsePlace")
    public boolean findAdPositionByUsePlace(@ApiParam(value = "广告使用位", required = true)
                                            @RequestParam("adUsePlace") AdUsePlace adUsePlace) {
        return this.advService.findAdPositionByUsePlace(adUsePlace);
    }

}


